//
//  RootViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/8/21.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "RootViewController.h"
#import "MySelfViewController.h"
#import "MainViewController.h"
#import "NoticeViewController.h"
#import "AttentionViewController.h"
#import "BuildingViewController.h"
#import "AgentListViewController.h"
#import "HouseListViewController.h"
#import "MakeMoneyViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tabBar.backgroundColor = [UIColor whiteColor];
    [self setupAllChildViewControllers];
}

- (void)setupAllChildViewControllers
{
    // 1.首页
    MainViewController *home = [[MainViewController alloc] init];
    [self setupChildViewController:home title:@"首页" imageName:@"首页_01" selectedImageName:@"首页_02" tag:0];
    
    // 2.经纪人
    AgentListViewController *message = [[AgentListViewController alloc] init];
    [self setupChildViewController:message title:@"经纪人" imageName:@"经纪人_01" selectedImageName:@"经纪人_02" tag:1];
    // 3.赚钱
    
    MakeMoneyViewController *discover = [[MakeMoneyViewController alloc] init];
    [self setupChildViewController:discover title:@"赚钱" imageName:@"赚钱_01" selectedImageName:@"赚钱_02" tag:2];

    
    // 4.个人中心
    MySelfViewController *me = [[MySelfViewController alloc] init];
    [self setupChildViewController:me title:@"我" imageName:@"我_01" selectedImageName:@"我_02" tag:3];
    
    for (UITabBarItem * i in self.tabBar.items) {
        
        i.titlePositionAdjustment = UIOffsetMake(0, -12);
        i.imageInsets = UIEdgeInsetsMake(-1, 0, 1, 0);
    }
}


- (void)setupChildViewController:(UIViewController *)childVc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName tag:(NSInteger)tag
{
    
    // 1.设置控制器的属性
    childVc.title = title;
    childVc.tabBarItem.image = [UIImage imageNamed:imageName];
    childVc.tabBarItem.tag = tag;
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 2.包装一个导航控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVc];
    nav.tabBarItem.titlePositionAdjustment = UIOffsetMake(0,-5);
    [self addChildViewController:nav];
}




@end
